<script setup lang="ts">
import { computed } from 'vue';

interface Props {
  /** 布局类型 */
  type?: 'default' | 'sidebar' | 'full';
  /** 自定义类名 */
  customClass?: string;
}

const props = withDefaults(defineProps<Props>(), {
  type: 'default',
  customClass: ''
});

const layoutClass = computed(() => {
  return `business-layout business-layout-${props.type} ${props.customClass}`;
});
</script>

<template>
  <div :class="layoutClass">
    <div v-if="$slots.header" class="business-header">
      <slot name="header" />
    </div>

    <div class="business-content">
      <div v-if="$slots.sidebar" class="business-sidebar">
        <slot name="sidebar" />
      </div>

      <div class="business-main">
        <div v-if="$slots.breadcrumb" class="business-breadcrumb">
          <slot name="breadcrumb" />
        </div>

        <div class="business-page-content">
          <slot />
          <RouterView />
        </div>
      </div>
    </div>

    <div v-if="$slots.footer" class="business-footer">
      <slot name="footer" />
    </div>
  </div>
</template>

<style scoped>
.business-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
}

.business-header {
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  z-index: 100;
}

.business-content {
  flex: 1;
  display: flex;
  min-height: 0;
}

.business-sidebar {
  width: 240px;
  height: 100% !important;
  background: #fff;
  border-right: 1px solid #f0f0f0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.04);
  z-index: 99;
}

.business-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.business-breadcrumb {
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  padding: 16px 24px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.business-page-content {
  flex: 1;
  padding: 24px;
  overflow: auto;
}

.business-footer {
  background: #fff;
  border-top: 1px solid #f0f0f0;
  padding: 16px 24px;
  text-align: center;
  color: #8c8c8c;
  font-size: 14px;
}

/* 布局类型变体 */
.business-layout-sidebar .business-content {
  flex-direction: row;
}

.business-layout-full .business-sidebar {
  display: none;
}

.business-layout-full .business-main {
  width: 100%;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .business-layout-sidebar .business-sidebar {
    position: fixed;
    left: -240px;
    top: 64px;
    bottom: 0;
    transition: left 0.3s ease;
    z-index: 1000;
  }

  .business-layout-sidebar.sidebar-open .business-sidebar {
    left: 0;
  }

  .business-page-content {
    padding: 16px;
  }

  .business-header {
    padding: 0 16px;
  }

  .business-breadcrumb {
    padding: 12px 16px;
  }

  .business-footer {
    padding: 12px 16px;
  }
}

/* 暗色主题适配 */
.dark .business-layout {
  background: #141414;
}

.dark .business-header {
  background: #1f1f1f;
  border-bottom-color: #303030;
}

.dark .business-sidebar {
  height: 100% !important;
  background: #1f1f1f;
  border-right-color: #303030;
}

.dark .business-breadcrumb {
  background: #1f1f1f;
  border-bottom-color: #303030;
}

.dark .business-footer {
  background: #1f1f1f;
  border-top-color: #303030;
  color: #999;
}
</style>
